package qdu.edu.com.fushanf4.service.sort;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import qdu.edu.com.fushanf4.utils.UtilConstants;

import java.io.IOException;

public class IntWritableSortMapper extends Mapper<LongWritable, Text, IntWritable, Text> {
    private final IntWritable keyOut = new IntWritable();
    private final Text valueOut = new Text();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        String[] keyValue = line.split(UtilConstants.RegexOfString.HORIZONTAL_TABULATION);
        valueOut.set(keyValue[0]);
        keyOut.set(Integer.parseInt(keyValue[1]));
        context.write(keyOut, valueOut);
    }
}
